package com.yuandian.management.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.po.ConfMpResourceParams;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.api.management.entity.ConfMpResource;
import com.yuandian.management.service.ConfMpResourceService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 中台监控-服务资源配置表-Controller
 * @author zfsn
 * @date 2023-4-18
 */
@Api(tags = "中台监控-资源配置")
@RestController
@RequestMapping("/mp/resource")
public class ConfMpResourceController {

	@Autowired
	private ConfMpResourceService confMpResourceService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键查询", notes = "通过主键查询资源配置，支持批量查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "主键数组", paramType = "path", required = true, dataType = "String", dataTypeClass = String.class)
	})
	@GetMapping("/queryByIds/{ids}")
	// @PreAuthorize("@pms.hasPermission('conf_mp_resource_view')")
	public R<List<ConfMpResource>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confMpResourceService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param params 中台监控-服务资源配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "current", value = "当前页", paramType = "body", required = true, dataType = "Long", dataTypeClass = Long.class),
			@ApiImplicitParam(name = "size", value = "每页条数", paramType = "body", required = true, dataType = "Long", dataTypeClass = Long.class),
			@ApiImplicitParam(name = "orders", value = "排序方式", paramType = "body", required = false, dataType = "OrderItem", dataTypeClass = OrderItem.class, allowMultiple = true),
			@ApiImplicitParam(name = "serviceIdList", value = "所属服务id集合", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class, allowMultiple = true),
			@ApiImplicitParam(name = "resourceType", value = "资源类型", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "url", value = "URL", paramType = "body", required = false, dataType = "String", dataTypeClass = Integer.class)
	})
	@PostMapping("/page")
	// @PreAuthorize("@pms.hasPermission('conf_mp_resource_view')")
	public R<Page<ConfMpResource>> page(@ApiIgnore @RequestBody ConfMpResourceParams params) {
		return confMpResourceService.page(params);
	}

	/**
	 * 新增数据
	 * @param params 中台监控-服务资源配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增资源", notes = "新增资源配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "serviceId", value = "所属服务id", paramType = "body", required = true, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "resourceType", value = "资源类型", paramType = "body", required = true, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "url", value = "URL", paramType = "body", required = true, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "timeout", value = "超时时间", paramType = "body", required = true, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "statisticalSign", value = "统计标识", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "remarks", value = "备注", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class)

	})
	@PostMapping("/save")
	// @PreAuthorize("@pms.hasPermission('conf_mp_resource_add')")
	public R<Boolean> save(@ApiIgnore @RequestBody ConfMpResourceParams params) {
		return confMpResourceService.saveWrap(params);
	}

	/**
	 * 通过主键更新数据
	 * @param params 中台监控-服务资源配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键更新", notes = "通过主键更新资源配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "serviceId", value = "所属服务id", paramType = "body", required = true, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "resourceType", value = "资源类型", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "url", value = "URL", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "timeout", value = "超时时间", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "statisticalSign", value = "统计标识", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "remarks", value = "备注", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class)

	})
	@PutMapping("/updateById")
	// @PreAuthorize("@pms.hasPermission('conf_mp_resource_update')")
	public R<Boolean> updateById(@ApiIgnore @RequestBody ConfMpResourceParams params) {
		return confMpResourceService.updateByIdWrap(params);
	}

	/**
	 * 通过主键删除数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键删除", notes = "通过主键删除资源配置，支持批量删除")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "主键数组", paramType = "path", required = true, dataType = "String", dataTypeClass = String.class)
	})
	@DeleteMapping("/removeByIds/{ids}")
	// @PreAuthorize("@pms.hasPermission('conf_mp_resource_delete')")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> idList) {
		boolean removeFlag = confMpResourceService.removeByIds(idList);
		return R.ok(removeFlag, removeFlag ? "删除成功" : "删除失败");
	}
}